<template>
  <div>
    <Row class="home-page-content" align="middle">
      <BtnPlain class="com-action-btn" type="primary" @click="goBack">返回</BtnPlain>
      <h3>经营信息详情</h3>
    </Row>

    <div class="home-page-content business-Info">
      <Row justify="space-between" align="middle">
        <Row align="middle">
          <BtnPlain
            v-if=" info.auditStatus && info.auditStatus !== 'Pass'"
            class="com-action-btn"
            :type="info.auditStatus | getAuditStatus"
          >{{ info.auditStatusName }}</BtnPlain>
          <BtnPlain
            v-else
            class="com-action-btn"
            :type="info.acceptStatus | getAcceptStatus"
          >{{ info.acceptStatusName }}</BtnPlain>
        </Row>
        <div class="publisher">
          <span>发布人 {{ info.publisher || '--' }}</span>
          <span>发布时间 {{ info.publishTime || '--'}}</span>
        </div>
      </Row>
      <Row class="mt-20" align="middle" v-if="info.auditStatus === 'NotPass'">
        <h4>拒绝理由</h4>
        <span class="ml-20">{{ info.auditRemark }}</span>
      </Row>
      <Row class="mt-20" justify="space-between" align="middle">
        <h3>{{ info.projectName }}</h3>
        <BtnText v-if="page === 'businessInformationManage'" type="primary" @BtnClick="goToHistory">变更历史记录</BtnText>
      </Row>
      <HistoryChange v-model="modelValueHistory" :busiInfoId="info.busiInfoId" />

      <!-- 重复率 -->
      <RepetitionRate :info="info" v-if="type !=='feedback' && type !=='receive'" />
      <!-- 经营信息 -->
      <BusinessInfo :info="info" v-if="type !=='feedback' && type !=='receive'" />
      <!-- 推送目标企业 -->
      <EnterpriseList
        v-if="info.auditStatus !== 'Pass'"
        ref="enterpriseList"
        :busiInfoId="info.busiInfoId"
        :initData="info.busiIndustryAssignList"
        :type="type"
      />

      <!-- 接收情况 -->
      <ReceiveList
        v-if="info.auditStatus === 'Pass'"
        :showFeedback="type !== 'receive'"
        :showTime="info.auditStatus !== 'NotPass'"
        :busiIndustryAssignList="info.busiIndustryAssignList"
      />

      <Row type="flex" justify="end" v-if="type ==='examine'">
        <BtnPlain type="primary" @click="onRefuse">拒绝</BtnPlain>
        <Button class="ml-20" type="primary" @click="onPass('Pass')">通过</Button>
      </Row>

      <Modal v-model="modalRefuse" width="400" title="审核拒绝理由" ok-text="提交" :mask-closable="false">
        <Input v-model="auditRemark" type="textarea" :rows="4" placeholder="请填写拒绝理由" />
        <Row slot="footer" type="flex" justify="center">
          <BtnPlain type="primary" @click="modalRefuse = false">取消</BtnPlain>
          <Button type="primary" @click="onSub">提交</Button>
        </Row>
      </Modal>

      <SourceInfo v-if="info.rootInformationEnum === 'Derivative'" v-model="modalValue" :parentId="tableParentId" />
    </div>
  </div>
</template>

<script>
import RepetitionRate from './common/repetitionRate.vue'
import BusinessInfo from './common/businessInfo.vue'
import EnterpriseList from './common/enterpriseList.vue'
import ReceiveList from './common/receiveList.vue'
import HistoryChange from '@/pages/components/historyChange'

import { busiInfoGetData, busiInfoAudit } from '@/api/businessInformationManage.js'
import { throttle } from 'lodash';

export default {
  name: "businessInformationDetails",
  components: { RepetitionRate, BusinessInfo, EnterpriseList, ReceiveList, HistoryChange },
  data () {
    return {
      type: 'view',
      info: {},
      auditRemark: '',
      modalRefuse: false,
      page: 'businessInformationManage',
      modelValueHistory: false
    };
  },
  created () {
    const { busiInfoId, type, page } = this.$route.query
    this.type = type
    this.page = page || 'businessInformationManage'
    this.busiInfoId = busiInfoId
    this.init(busiInfoId)
  },
  methods: {
    async init (busiInfoId) {
      this.info = await busiInfoGetData({ busiInfoId })
    },
    goBack () {
      this.$router.replace({ path: this.page });
    },
    onRefuse () {
      this.modalRefuse = true
    },
    onSub () {
      if (!this.auditRemark.trim()) {
        this.$Message.error('拒绝理由必填');
        return
      }
      this.onPass('NotPass', this.auditRemark)

    },
    goToHistory () {
      this.modelValueHistory = true
      // this.$router.push({ path: "/businessInfoHistory", query: { busiInfoId: this.busiInfoId, type: this.type } });
    },
    onPass: throttle(async function (auditStatus = 'Pass', auditRemark = '') {
      const busiIndustryAssignList = this.$refs.enterpriseList.getData()
      const request = {
        busiIndustryAssignList,
        auditStatus,
        busiInfoId: this.info.busiInfoId,
        auditRemark
      }
      await busiInfoAudit(request)
      if (auditStatus === 'Pass') {
        this.$Message.success('审核已通过！');
      } else {
        this.$Message.error('审核已拒绝！');
      }
      this.goBack()
    }, 500)
  },
}
</script>

<style lang='less' scoped>
.business-Info {
  margin-top: 20px;
}

.publisher {
  > span {
    margin-left: 20px;
  }
}

.mt-20 {
  margin-top: 20px;
}

.ml-20 {
  margin-left: 20px;
}

.countdown {
  margin-left: 10px;
  font-size: 20px;
  font-weight: 500;
  color: #ed4014;
}
</style>
